//
//  CitySelecter.m
//  GLuckyTransport
//
//  Created by mac on 15/8/8.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "CitySelecter.h"
#import "ProvinceBoard.h"
#import "CityBoard.h"

@interface CitySelecter ()

@end

@implementation CitySelecter

DEF_NOTIFICATION2(SelecterProvinceChanged, CitySelecter)
DEF_NOTIFICATION2(SelecterCityChanged, CitySelecter)

@synthesize province;
@synthesize city;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self observeNotification:[CitySelecter SelecterProvinceChanged]];
    [self observeNotification:[CitySelecter SelecterCityChanged]];
    
    [self.customNavLeftBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavLeftBtn setFrame:CGRectMakeBound(32, 32)];
    
    
    [self.customNavRightBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavRightBtn setFrame:CGRectMakeBound(32, 32)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (CGFloat)columWidthForPosition:(ColumPosition)position{
    CGFloat width = 0;
    if (position==ColumPositionLeft) {
        width = self.view.width/2;
        
    }else if (position==ColumPositionRight){
        width = self.view.width/2;
    }
    return width;
}
- (UIViewController *)columControllerForPosition:(ColumPosition)position{
    UIViewController *vv = nil;
    if (position==ColumPositionLeft) {
        vv = [ProvinceBoard board];
        
    }else if (position==ColumPositionRight){
        vv = [CityBoard board];
    }
    
    return vv;
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {//customNavLeftBtn
            [self backAndRemoveWithAnimate:YES];
        }else if ([btn is:@"rightBtn"]){//customNavRightBtn
            HMUIPopoverView *picker = [HMUIPopoverView spawnWithReferView:btn inView:nil];
            picker.eventReceiver = self;
            
            picker.showGlass = NO;
            
            picker.contentView = [[CitySelecter alloc]init].view;
            picker.contentRect = CGRectMakeBound(self.view.width-30, 300);
            [picker showWithAnimated:YES];
        }
    }
}

ON_NOTIFICATION3(CitySelecter, SelecterProvinceChanged, noti){
    self.province = [noti.object valueForKey:@"state"];
}

ON_NOTIFICATION3(CitySelecter, SelecterCityChanged, noti){
    self.city = noti.object;
}

@end
